package com.cysyz.module.permission.stateless;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;

public class SpringBeanUtils {
	private static ApplicationContext applicationContext = null;

	public static void setApplicationContext(ApplicationContext applicationContext) {
		SpringBeanUtils.applicationContext = applicationContext;
	}

	/**
	 * 获取对象
	 * 
	 * @param id 
	 * @return Object 一个以所给名字注册的bean的实例
	 * @throws BeansException
	 */
	public static Object getBean(String id) {
		return applicationContext.getBean(id);
	}

	/**
	 * 获取bean
	 * @param clazz
	 * @return
	 */
	public static <T> T getBean(Class<T> clazz){

		return (T) applicationContext.getBean(clazz);
	}
	
	/**
	 * 获取bean
	 * @param id
	 * @param clazz
	 * @return
	 */
	public static <T> T getBean(String id,Class<T> clazz){

		return (T) applicationContext.getBean(id, clazz);
	}

	public static ApplicationContext getApplicationContext() {
		return applicationContext;
	}
}
